package com.ayitubie.refuelmapprovider.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.ayitubie.refuelmapprovider.entity.Test;
import com.ayitubie.refuelmapprovider.entity.TestExample;
import com.ayitubie.refuelmapprovider.mapper.GasStationForMapMapper;
import com.ayitubie.refuelcommon.entity.GasStationForMap;
import com.ayitubie.refuelcommon.service.gasStationMapServ;
import com.ayitubie.refuelmapprovider.mapper.TestMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
@Service
public class gasStationsForMapImpl implements gasStationMapServ {
    @Autowired
    GasStationForMapMapper gasStationForMapMapper;
    @Autowired
    TestMapper testMapper;

    @Autowired
    ThreadPoolExecutor executor;

    @Override
    public List<GasStationForMap> getGasStrionsForMap(int userId) {
        log.info("核心线程数：{}", executor.getCorePoolSize());
        log.info("最大线程数：{}", executor.getMaximumPoolSize());
        log.info("线程销毁时间：{}", executor.getKeepAliveTime(TimeUnit.SECONDS));
        log.info("任务队列长度：{}", executor.getQueue().size());
        log.info("拒绝处理方式：{}", executor.getRejectedExecutionHandler());
        List<GasStationForMap> list = list = new ArrayList<GasStationForMap>();
        try {
            CompletableFuture<List<GasStationForMap>> future = CompletableFuture.supplyAsync(() -> {
                return gasStationForMapMapper.getAllStationForMap(userId);
            }, executor);
            list = future.get();
            log.info("异步任务输入：{}", list.toString());
            TestExample testExample = new TestExample();
            testExample.createCriteria().andStationNameEqualTo("aaa").andCreateTimeIsNotNull();
            List<Test> testList = testMapper.selectByExample(testExample);
            log.info("test list :{}",testList);
        } catch (Exception e) {
            e.printStackTrace();
            Thread.currentThread().interrupt();
        }
        return list;
    }
}